﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using MongoDB.Driver;

namespace PoemGame.Repository.MongoDb.Test
{
    internal class Utility
    {
        public static IConfigurationRoot GetConfiguration()
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();

            return configuration;
        }

        public static IMongoDatabase GetDb(IConfigurationRoot configuration)
        {
            var conn = configuration["MongoDb:Connection"];
            var dbName = configuration["MongoDb:DbName"];

            var client = new MongoClient(conn);
            //获得数据库、集合
            return  client.GetDatabase(dbName);
        }
    }
}
